/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mii.dao.impl;

import java.util.List;
import javax.persistence.EntityManager;
import mii.dao.ComplainDAO;
import mii.ejb.entity.Complain;

/**
 *
 * @author TEKNISI
 */
public class ComplainDAOImpl implements ComplainDAO{
private EntityManager em;
    
    public ComplainDAOImpl(EntityManager em){
        this.em = em;
    }
    @Override
    public List<Complain> getAll() {
         return this.em.createQuery("SELECT c FROM Complain c").getResultList();
    }

    @Override
    public Complain getById(long id) {
        return this.em.find(Complain.class, id);
    }

    @Override
    public Complain getByKode(String kodeComp) throws Exception {
        return this.em.find(Complain.class, kodeComp);
    }

    @Override
    public void insert(Complain complain) throws Exception {
        this.em.persist(complain);
    }

    @Override
    public void update(Complain complain) throws Exception {
        this.em.merge(complain);
    }

    @Override
    public void delete(Complain complain) throws Exception {
         this.em.remove(complain);
      }
    
    
}
